﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.IO.IsolatedStorage;
using System.Xml.Linq;
using System.Linq;
using System.IO;
using Common.Library;


namespace ActivityTracker.Library
{
    public class Charts
    {
        IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
        IsolatedStorageFileStream isoStream;
        XDocument xdoc;

        public List<string> GetYears()
        {
            List<string> yearsList = new List<string>();
            try
            {
                if (isoStore.FileExists("ActivityTracker/TotalDurations.xml"))
                {
                    isoStream = new IsolatedStorageFileStream("ActivityTracker/TotalDurations.xml", FileMode.Open, isoStore);
                    xdoc = XDocument.Load(isoStream);
                    isoStream.Close();
                    var activitylist = (from t in xdoc.Descendants("monthlyduration") select t);
                    foreach (XElement elem in activitylist.Elements())
                    {
                        
                        yearsList.Add(elem.Name.LocalName.Substring(4, 4));
                        if (yearsList.Count == 0)
                            yearsList.Add(DateTime.Now.Year.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Exception exnew = new Exception("Exception in GetYears Method In ActivityTracker.Library.Charts.Charts file.\n\n" + ex.Message + "\n\n Stack Trace:- " + ex.StackTrace);
                throw exnew;
            }
            yearsList.Sort();
            return yearsList;
        }

        public List<string> LoadProgressChartMenu(string actId)
        {
            List<string> mapmenulist = new List<string>();
            try
            {
                Maps objMaps = new Maps();
                bool isMapVisible = objMaps.IsMapVisible(actId);
                bool GeoLocationStatus = SettingsHelper.getBoolValue("GeoLocationStatus");
                if (isMapVisible && GeoLocationStatus)
                {
                    mapmenulist.Add("daily");
                    mapmenulist.Add("monthly");
                    mapmenulist.Add("yearly");
                    mapmenulist.Add("activity map");
                }
                else
                {
                    mapmenulist.Add("daily");
                    mapmenulist.Add("monthly");
                    mapmenulist.Add("yearly");
                }
            }
            catch (Exception ex)
            {
                Exception exnew = new Exception("Exception in LoadProgressChartMenu Method In ActivityTracker.Library.Charts.Charts file\n\n" + ex.Message + " \n\n Stack Trace \n" + ex.StackTrace + "\n\n");
                throw exnew;
            }
            return mapmenulist;
        }

        public List<string> GetMonths()
        {
            List<string> monthList = new List<string>();
            monthList.Add("Jan");
            monthList.Add("Feb");
            monthList.Add("Mar");
            monthList.Add("Apr");
            monthList.Add("May");
            monthList.Add("Jun");
            monthList.Add("Jul");
            monthList.Add("Aug");
            monthList.Add("Sep");
            monthList.Add("Oct");
            monthList.Add("Nov");
            monthList.Add("Dec");
            return monthList;
        }
    }

    public enum ChartType
    {
        Bar,
        Pie
    }
}
